import blog from '@/api/blog.js'

export default {
  data() {
    return {
      blogs: [],
      total: 0,
      page: 1
    }
  },

  created(){
    this.page = parseInt(this.$route.query.page) || 1
    blog.getIndexBlogs().then(res =>{
      console.log(res)
      this.blogs = res.data
      this.total = res.total
      this.page = res.page
    })
  },

  methods: {
    // onClick1() {
    //   this.$message.error('23333');
    // },
    // onClick2() {
    //   this.$alert('这是一段内容', '标题名称', {
    //     confirmButtonText: '确定',
    //     callback: action => {
    //       this.$message.success('点了确定')
    //     }
    //   });
    // }
    onPageChange(newPage){
      console.log(newPage)
      blog.getIndexBlogs({page: newPage}).then(res =>{
        console.log(res)
        this.blogs = res.data.reverse()
        console.log('测试')
        console.log(this.blogs)
        this.total = res.total
        this.totalPage = res.totalPage
        this.page = res.page
        this.$router.push({ path: '/', query:{ page: newPage}})
      })
    }
  }
}